import sys
from PyQt5.QtWidgets import QApplication, QWidget, QSlider, QVBoxLayout
from PyQt5.QtCore import Qt


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.h_slider = QSlider(Qt.Horizontal)
        self.v_slider = QSlider(Qt.Vertical)

        # 设置滑块的最小值0、最大值100、步长1、默认值50
        self.h_slider.setMinimum(0)
        self.h_slider.setMaximum(100)
        self.h_slider.setSingleStep(1)
        self.h_slider.setValue(50)
        self.h_slider.setTickPosition(QSlider.TicksBelow)   # 设置刻度位置: 下面
        self.h_slider.setTickInterval(10)                  # 设置刻度间隔: 10
        self.h_slider.valueChanged.connect(self.signal_callback_h_slider)   # 滑块值改变时触发信号

        self.v_slider.setMinimum(1)
        self.v_slider.setMaximum(10)
        self.v_slider.setSingleStep(2)
        self.v_slider.setValue(1)
        self.v_slider.setTickPosition(QSlider.TicksRight)   # 设置刻度位置: 右面 
        self.v_slider.setTickInterval(2)                  # 设置刻度间隔: 2
        self.v_slider.sliderReleased.connect(self.signal_callback_v_slider)   # 滑块值改变时触发信号

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.h_slider)
        self.layout.addWidget(self.v_slider)
        self.setLayout(self.layout)

        self.setGeometry(0, 0, 200, 200)
        self.show()

    def signal_callback_h_slider(self, value):
        print(value)
    
    def signal_callback_v_slider(self):
        value = self.v_slider.value()
        print(value)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())
